package com.wuchaooooo.service.zjutsds.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.druid.util.StringUtils;
import com.wuchaooooo.service.zjutsds.pojo.vo.VScore;
import com.wuchaooooo.service.zjutsds.service.ScoreService;

/**
 * Created by arthur on 01/19/2020.
 */
@Controller
public class SFPController {
	@Autowired
	private ScoreService scoreService;

	@RequestMapping(value = "/SfpPage", method = RequestMethod.GET)
	public String returnLogin() {
		return "SfpPage";
	}
    @RequestMapping(value = "/SfpPage", method = RequestMethod.POST)
    public String getResult(VScore vScore, Map<String, Object> model) {
    	model.put("vScore", vScore);
    	if (StringUtils.isEmpty(vScore.getSubject())){
    		model.put("error", "请选择科类！");
    		return "SfpPage";
    	}
    	if (StringUtils.isEmpty(vScore.getYear())){
    		model.put("error", "请选择年份！");
    		return "SfpPage";
    	}
    	if (StringUtils.isEmpty(vScore.getScore())){
    		model.put("error", "请输入分数！");
    		return "SfpPage";
    	}

    	if (!StringUtils.isEmpty(vScore.getCategoryCode()) && vScore.getCategoryCode().split(",").length > 3){
    		model.put("error", "选择的专业类不能超过三个！");
    		return "SfpPage";
    	}
    	
    	Map<String, List<VScore>>  map = scoreService.getUniList(vScore);
    	if (map.size() == 0){
    		model.put("error", "根据条件检索的数据为0，请调整检索条件。");
    		return "SfpPage";
    	}
    	
        model.put("uniMap", map);
        return "SfpPage";
    }

}
